package service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import dao.CustomerDao;
import pojo.Customer;
import service.CustomerManager;


@Service(value = "customerManagerImpl2")
public class CustomerManagerImpl2 implements CustomerManager{
	
	@Resource(name = "customerDaoImpl")
	private CustomerDao customerDao;
	
	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}


	@Override
	public synchronized Customer add(Customer c) {
		String id = UUID.randomUUID().toString();
		c.setId(id);
		customerDao.addCustomer(c);
		return c;
	}


	@Override
	public synchronized List<Customer> getlist() {
		return customerDao.findAllCustomer();
	}


	@Override
	public synchronized boolean delete(String id) {
		int m = customerDao.deleteCustomerById(id);
		if(m==1)return true;
		else return false;
	}


	@Override
	public Customer updateCustomer(Customer c) {
		customerDao.updateCustomer(c);
		return c;
	}
	
}
